import numpy as np
import re

data = np.load('./data_task2/average.npz')
train = data['trainRes']
test = data['testRes']

tmp = {}

f = open('./result_merger/traffic_volume.csv', 'r')
first = True
for line in f.readlines():
    if first:
        first = False
        continue
    items = line.split(',')
    tollgate_id = int(items[0])
    direction = int(items[3])
    if tollgate_id == 1:
        subtask = direction
    elif tollgate_id == 2:
        subtask = 2
    else:
        subtask = 3 + direction
    day = int(re.findall(r'\d+-\d+-(\d+)', items[1])[0])
    hour = int(re.findall(r'(\d+):\d+:\d+', items[1])[0])
    if hour < 10:
        v = (subtask, day - 25, 0)
    else:
        v = (subtask, day - 25, 1)
    if not tmp.has_key(v):
        tmp[v] = 0.0
    tmp[v] += float(items[4])

for (key, value) in tmp.items():
    test[key[0], key[1], key[2]*2+1] = value / 6

np.savez('./data_task2/average_test.npz', trainRes=train, testRes=test)
